import random

def genRandomCvtColor():
    return """<cvtColor>
<code> CV_RGB2GRAY </code>
</cvtColor>\n"""

def genRandomResize():
    options = ["INTER_NEAREST",
               "INTER_LINEAR",
               "INTER_AREA",
               "INTER_CUBIC",
               "INTER_LANCZOS4"]
               
    base = """<resize>
<scaleFactorX> %s </scaleFactorX>
<scaleFactorY> %s </scaleFactorY>
<interpolation> %s </interpolation>
</resize>\n"""
    
    x = str(random.random() * 3)
    y = str(random.random() * 3)
    interpolation = random.choice(options)
    
    return base % (x,y,interpolation)
    
def genRandomGaussianBlur():
    kSize_options = ["3",
               "5",
               "7",
               "9",
               "11"]
    borderType_options = ["BORDER_CONSTANT",
               "BORDER_DEFAULT",
               #"BORDER_ISOLATED",
               "BORDER_REFLECT",
               "BORDER_REFLECT_101",
               "BORDER_REPLICATE",
               "BORDER_TRANSPARENT",
               #"BORDER_WRAP"
               ]          
    base = """<GaussianBlur>
<kSize> %s </kSize>
<sigmaX> %s </sigmaX>
<sigmaY> %s </sigmaY>
<borderType> %s </borderType>
</GaussianBlur>\n"""
    
    x = str(random.random() * 3)
    y = str(random.random() * 3)
    kSize = random.choice(kSize_options)    
    borderType = random.choice(borderType_options)    
    
    return base % (kSize, x,y,borderType)

    
def genRandomEffects():    
    options = [genRandomCvtColor,genRandomResize,genRandomGaussianBlur]
    n = random.randint(1,len(options))
    out = ""
    random.shuffle(options)
    for i in xrange(n):
        out += options.pop()()
    return out